package com.my.study.structures.stack;

import java.util.Scanner;
import java.util.Stack;

/**
 * @author Carlos
 * @version 1.0
 * @Description TODO
 * @date 2021/6/9 21:37
 **/
public class TestStack {

    public static void main(String[] args) {
        ArrayStack stack = new ArrayStack(4);
        String key = "";
        boolean loop = true;

        Scanner scanner = new Scanner(System.in);

        while (loop) {
            System.out.println("show：显示栈");
            System.out.println("exist：退出");
            System.out.println("push：入栈");
            System.out.println("pop：出栈");
            System.out.println("请输入你的选择：");
            key = scanner.next();

            switch (key) {
                case "show":
                    stack.list();
                    break;
                case "exist":
                    scanner.close();
                    loop = false;
                    break;
                case "push":
                    System.out.println("请输入一个入栈的数：");
                    int value = scanner.nextInt();
                    stack.push(value);
                    break;
                case "pop":
                    try {
                        System.out.printf("出栈的数据%d\n",stack.pop());
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出~~~~");

    }

    private static void test01() {
        Stack<String> stack = new Stack<>();

        stack.push("A");
        stack.push("B");
        stack.push("C");

        while (!stack.empty()) {
            System.out.println(stack.pop());
        }
    }

}
